home *** CD-ROM | disk | FTP | other *** search
- // DO NOT import this into the global namespace, but instead
- // import it into your own namespace wrapper
-
- var EXPORTED_SYMBOLS = ["VERSIONS_MANAGER"];
-
- Components.utils.import("resource://glydo/utils/prototype_xul_1_6_0_3_modified.jsm");
- Components.utils.import("resource://glydo/utils/Utils.jsm");
- Components.utils.import("resource://glydo/utils/Prefs.jsm");
- Components.utils.import("resource://glydo/utils/WindowUtils.jsm");
- Components.utils.import("resource://glydo/storage/LoggingDB.jsm");
- Components.utils.import("resource://glydo/ClientInfo.jsm");
- Components.utils.import("resource://glydo/application/ReportsManager.jsm");
-
- //The quit application observer topic
- const OBSERVER_TOPIC_QUIT_APPLICATION = "quit-application-requested";
- // The extension manager action requested observer topic
- const OBSERVER_TOPIC_EM_ACTION_REQUESTED = "em-action-requested";
-
- var WELCOME_PAGES_BY_UPGRADE_VERSIONS = [
- {version: "0", url: "http://www.glydo.com/welcome/0.9.19/welcome.html"},
- {version: "0.9.1debug", url: "http://www.glydo.com/welcome/0.9.19/upgrade.html"},
- {version: "0.9.20debug", url: null}
- ];
-
- var VERSIONS_MANAGER = ({
-
- init: function() {
- this.pendingUninstall = false;
- this.pendingDisable = false;
- this.getJustUpgradedFromVersion();
- this.registerObservers();
- },
-
- registerObservers: function() {
- var observerService = Components.classes["@mozilla.org/observer-service;1"].
- getService(Components.interfaces.nsIObserverService);
- observerService.addObserver(this, OBSERVER_TOPIC_QUIT_APPLICATION, false);
- observerService.addObserver(this, OBSERVER_TOPIC_EM_ACTION_REQUESTED, false);
- },
-
- unregisterObservers: function() {
- var observerService = Components.classes["@mozilla.org/observer-service;1"].
- getService(Components.interfaces.nsIObserverService);
- observerService.removeObserver(this, OBSERVER_TOPIC_QUIT_APPLICATION);
- observerService.removeObserver(this, OBSERVER_TOPIC_EM_ACTION_REQUESTED);
- },
-
- observe: function(subject, topic, data) {
- switch(topic) {
- case OBSERVER_TOPIC_QUIT_APPLICATION:
- this.cleanupIfStoppingUsage();
- break;
- case OBSERVER_TOPIC_EM_ACTION_REQUESTED:
- this.updatePendingActions(subject, data);
- break;
- }
- },
-
- cleanupIfStoppingUsage: function() {
- // Note: this function may be called multiple times
- if (this.pendingUninstall || this.pendingDisable) {
-
- REPORTS_MANAGER.sendReportForce();
- }
- if (!this.pendingUninstall && !this.pendingDisable) {
- REPORTS_MANAGER.sendReportIfNecessary();
- }
- this.unregisterObservers();
- },
-
- updatePendingActions: function(subject, data) {
- subject.QueryInterface(Components.interfaces.nsIUpdateItem);
- if (CLIENT_INFO.appId == subject.id) {
- switch (data) {
- case "item-cancel-action":
- this.pendingUninstall = false;
- this.pendingDisable = false;
- LOGGING_DB.logUserEvent("application.install","cancel_action",null,null);
- REPORTS_MANAGER.sendReportForce();
- break;
- case "item-uninstalled":
- this.pendingUninstall = true;
- LOGGING_DB.logUserEvent("application.install","uninstall",null,null);
- REPORTS_MANAGER.sendReportForce();
- if ("http://www.glydo.com/survey/uninstall" != "") {
- WindowUtils.goToURL(null,"http://www.glydo.com/survey/uninstall");
- }
- break;
- case "item-disabled":
- this.pendingDisable = true;
- LOGGING_DB.logUserEvent("application.install","disable",null,null);
- REPORTS_MANAGER.sendReportForce();
- break;
- }
- }
- },
-
- getJustUpgradedFromVersion: function() {
- var last = Prefs.last_installed_version;
- this.justUpgradedFromVersion = null;
- if (last) {
- if (last == CLIENT_INFO.version) {
- return;
- }
- this.justUpgradedFromVersion = last;
- LOGGING_DB.logUserEvent("application.install","upgrade",
- {
- from: last
- },null);
- } else {
- this.justUpgradedFromVersion = "0";
- LOGGING_DB.logUserEvent("application.install","install",null,null);
- }
- Prefs.last_installed_version = CLIENT_INFO.version;
- },
-
- showWelcomePageIfNecessary: function(parent) {
- if (this.justUpgradedFromVersion) {
- var welcomePageURL = this.findWelcomePageURL();
- if (welcomePageURL && welcomePageURL != "") {
- Prototype.F.delay(function() {
- WindowUtils.goToURL(parent,welcomePageURL,'new-tab');
- },1);
-
- }
- }
- },
-
- findWelcomePageURL: function() {
- for (var i= 0; i < WELCOME_PAGES_BY_UPGRADE_VERSIONS.length; ++i) {
- var entry = WELCOME_PAGES_BY_UPGRADE_VERSIONS[i];
- var c = Utils.compareVersionNumbers(this.justUpgradedFromVersion,entry.version);
- if (c > 0) {
- break;
- }
- }
- if (i < 1 || i > WELCOME_PAGES_BY_UPGRADE_VERSIONS.length) {
- return null;
- }
- return WELCOME_PAGES_BY_UPGRADE_VERSIONS[i-1].url;
- },
-
- });
-
- VERSIONS_MANAGER.init();
-
-